const { Fruit } = require('../models/fruit');

const Delete = async ctx => {

  let { id, page=1, keyword='' } = ctx.query;
  let ids = id.includes('_')?id.split('_').map(n=>+n):+id;
  let err = 0;
  let desc = '';

  try {
    await Fruit.destroy({ where: { id:ids } });
    desc = '删除水果成功！';
  } catch (error) {
    desc = '执行出错！';
    err = 10001;
  }

  ctx.render('result.html',{
    err,
    desc,
    page,
    keyword
  });

}

module.exports = {
  'GET /delete': Delete,
}